import React, {Component} from 'react';
//import {CustomCachedImage} from "react-native-img-cache";
import AutoHeightImage from 'react-native-auto-height-image';
//https://github.com/vivaxy/react-native-auto-height-image

 export default class AutoImage extends Component {

    //构造函数
    constructor(props) {
        super(props);
        this.state = {
            errorcount:0,
            source:this.props.source,
            sourcebase:this.props.source,
            //height:0,
            width:this.props.width,
        };
    }

    componentDidMount() {
    }

    //组件卸载
    componentWillUnmount() {

    }

    componentWillReceiveProps(nextProps) {
    }

    render() {
        return (
            <AutoHeightImage
            {...this.props}
                    //fallbackSource={image}
            errorcount={this.state.errorcount}
            onError={(e)=>{
                if(this.state.width!=0)
                {
                    this.setState({width:0});
                    console.log("【atuoimage】图片加载失败2:重试:默认错误图片");
                }
                // this.state.errorcount=this.state.errorcount+1;
                // if(this.state.errorcount>1)
                // {
                //     //this.setState({source:),errorcount:this.state.errorcount});
                // }
                // else
                // {
                //     this.setState({source:{uri:this.state.sourcebase.uri, cache: 'force-cache'},errorcount:this.state.errorcount});
                //     console.log("【atuoimage】图片加载失败2:重试:"+this.state.errorcount+"uri:"+this.state.sourcebase.uri);
                //     console.log(e);
                // }
                if(this.props.onError)
                    this.props.onError(e);
            }}
                  >
                 
                  </AutoHeightImage>
        );
    }
}